local skill = fk.CreateSkill {
    name = "ym1__zhang",
}
skill:addEffect("viewas",{
    pattern = "peach",
    view_as = function(self, player, cards)
        if #cards ~= 1 then return nil end
        local c = Fk:cloneCard("peach")
        c.skillName = skill.name
        c:setMark(skill.name, cards[1])
        return c
    end,
    card_filter = function(self, player, to_select, selected)
        local card = Fk:getCardById(to_select)
        return #selected == 0 and card.color == Card.Black
    end,
    card_num = 1,
    before_use = function (self, player, use)
        local room = player.room
        player:broadcastSkillInvoke("ym1__zhang")
        local put = use.card:getMark(skill.name)
        if put ~= 0 and table.contains(player:getCardIds("he"), put) then
            room:throwCard(put, skill.name, player, player)
        end
        local targets = table.filter(room.alive_players, function(p)
            return not table.contains(p.sealedSlots, Player.ArmorSlot)
        end)
        if #targets == 0 then return "" end
        local tos = room:askToChoosePlayers(player,{
            min_num = 1,
            max_num = 1,
            targets = targets,
            skill_name = skill.name,
            prompt = "#ym1__zhang-choose",
            cancelable = false,
            no_indicate = true,
        })
        if #tos > 0 then
            local orig_card = Fk.all_card_types["ym__breastplate"]
            if not orig_card then return "" end
            local card = room:printCard("ym__breastplate", orig_card.suit, orig_card.number)
            room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
            room:useCard{from = player, tos = {tos[1]}, card = card}
        end
        room:setPlayerMark(player, "ym1__zhang-failed-phase", 1)
        return ""
    end,
    enabled_at_play = function (self, player)
        return #table.filter(player:getCardIds("he"), function (id)
            return Fk:getCardById(id).color == Card.Black
        end) > 0 and player:getMark("ym1__zhang-failed-phase") == 0
    end,
    enabled_at_response = function (self, player, response)
        return not response and #table.filter(player:getCardIds("he"), function (id)
            return Fk:getCardById(id).color == Card.Black
        end) > 0 and player:getMark("ym1__zhang-failed-phase") == 0
    end,
})
for _, value in ipairs({fk.AskForCardUse, fk.AskForCardResponse, fk.AfterAskForCardUse, fk.AfterAskForCardResponse, fk.PreCardUse, fk.CardUseFinished, fk.SkillEffect, fk.AfterSkillEffect}) do
    skill:addEffect(value,{
        can_refresh = function (self, event, target, player, data)
            return player:getMark("ym1_zhang-failed-phase") ~= 0
        end,
        on_refresh = function (self, event, target, player, data)
            local room = player.room
            room:setPlayerMark(player, "ym1_zhang-failed-phase", 0)
        end,
    })
end
Fk:loadTranslationTable{
    ["ym1__zhang"] = "障",
    [":ym1__zhang"] = "当你需要使用【桃】时，你可弃置一张黑色牌，令一名角色装备额外牌堆中的一张【护心镜】。",
    ["#ym1__zhang_trigger"] = "障",
    ["#ym1__zhang-choose"] = "障：令一名角色装备额外牌堆中的一张【护心镜】",
    ["#ym1__zhang-cost"] = "障：是否弃置一张黑色牌，令一名角色装备一张【护心镜】",

    ["$ym1__zhang1"] = "敌人会锁定我，让他们放马过来！",
    ["$ym1__zhang2"] = "有本事，就跟紧我！",
}
return skill